package ch14;

import java.util.LinkedList;

/**
 * Created by 春旺 on 2017/10/9.
 */
public class LinkedStack2<T> implements Stack {
    LinkedList linkedList = new LinkedList();
    @Override
    public void push(Object element) {
        linkedList.add(element);

    }

    @Override
    public Object pop() {
        return null;
    }

    @Override
    public Object peek() {
        return null;
    }

    @Override
    public boolean isEmpty() {
        boolean re = true;
        for (int i = 0;i < linkedList.size();i++){
            if (linkedList.get(i) != null){
                re = false;
                break;
            }
        }

        return re;
    }

    @Override
    public int size() {
        int size = 0;
        for (int i = 0;i < linkedList.size();i++){
            if (linkedList.get(i) != null){
              size ++;
            }
        }
        size = linkedList.size();
        return size;
    }

    @Override
    public String toString() {
        String result = null;

            for (int i = 0;i < linkedList.size();i++){
                if (linkedList.get(i) != null){
                    result += linkedList.get(i);
                }
            }

            return result;

    }
}
